﻿using System;
using System.Collections;
using jSLApp.Client.MainService;
using jSLCore.Client.Presentation.BaseControl;
using jSLCore.Client.Presentation.BaseControl.DialogMessage;

namespace jSLApp.Client.Forms
{
    public partial class AdministratorAccessRoles : DialogControl
    {
        public AdministratorAccessRoles()
        {
            InitializeComponent();
        }

        public override void OkClicked()
        {
            DoWork("Сохранение ролей",(sender, args) =>
                                          {
                                              Communication.Proxy.SaveAllRoles((Role[]) args.Argument);
                                          },(o, eventArgs) =>
                                                                {
                                                                    if(eventArgs.Error==null)
                                                                    {
                                                                        InfoBox.ShowDialog("Роли сохранены");
                                                                        InvokeDataSelected();
                                                                    }
                                                                },grid.ItemsSource);
        }

        public override bool IsStandartOkCancelEnabled
        {
            get { return true; }
        }

        public override void LoadInitialData()
        {
            DoWork("Загрузка ролей",(sender, args) =>
                                        {
                                            args.Result = Communication.Proxy.GetAllRoles();
                                        },(o, eventArgs) =>
                                                              {
                                                                  if(eventArgs.Error==null)
                                                                  {
                                                                      grid.ItemsSource = (IEnumerable) eventArgs.Result;
                                                                  }
                                                              });
        }
    }
}
